<template>

  <smart-page id="system-menu">
    <template #actions>
      <a-button v-auth="Acl.PRODUCT_PROFILE_DELETE" :disabled="selectedKeys.length === 0" @click="onDelete()">批量删除</a-button>
      <a-button v-auth="Acl.PRODUCT_PROFILE_ADD" type="primary" @click="editCtr.open()">新增档案</a-button>
    </template>
    <template #search>
      <smart-search :query-array="PROFILE_SEARCH" @on-handler="onSearch"/>
    </template>
    <a-table v-model:selectedKeys="selectedKeys"
             :table-layout-fixed="theme.layoutFixed"
             :row-selection="rowSelection"
             :columns="PROFILE_COLUMNS"
             :row-key="rowKey"
             :column-resizable="theme.resizable"
             :bordered="theme.bordered"
             :stripe="theme.stripe"
             :sticky-header="theme.sticky"
             :hoverable="theme.hoverAble"
             :pagination="pagination"
             :loading="theme.loading"
             :data="dataSource"
             @page-change="onPageChange"
             @page-size-change="onPageSizeChange">


      <template #icon="{record}">
        <smart-game-icon :icon="record.icon" :width="50" />
      </template>

      <template #action="{ record }">
        <a-space size="mini">
          <a-link v-auth="Acl.PRODUCT_PROFILE_UPDATE" @click="editCtr.open(record)" v-text="'修改'"/>
          <a-link v-auth="Acl.PRODUCT_PROFILE_DELETE" v-if="record.parentCode !=='0'" status="danger" @click="onDelete(record)"> 删除</a-link>
        </a-space>
      </template>
    </a-table>
    <edit-modal v-if="editCtr.show" :record="editCtr.record" @cancel="editCtr.close"/>
<!--    <refine-modal v-if="readCtr.show" :record="readCtr.record" @cancel="readCtr.close"/>-->
  </smart-page>


</template>
<script lang="ts" setup name="system-settings-menu">
import {onMounted} from 'vue';
import {TablePage} from "@/libs/core";
import {PROFILE_COLUMNS} from "../../resource/colums";
import {ProductHttp} from "../../resource/http";
import {PROFILE_SEARCH} from "../../resource/search";
import EditModal from './edit.vue'
import {Acl} from "@/libs/acl";
// import RefineModal from './refine.vue'

const pageConfig = {title: '列表', rowKey: 'id', nameKey: 'name',}
const {getProfileList  , delProfile} = ProductHttp
const tablePage = new TablePage(pageConfig).setFetchXhr(getProfileList).setDeleteXhr(delProfile).setPermission(Acl.PRODUCT_PROFILE_PAGE_LIST);

const {theme, pagination, rowKey, dataSource, rowSelection, selectedKeys, editCtr} = tablePage
const {onFetch, onPageChange, onPageSizeChange, onDelete, onSearch} = tablePage
onMounted(() => onFetch())
</script>

<style lang="less" scoped>
:deep( .smart-page-header) {
  margin-bottom: 1px !important;
}
</style>